Main
Plotting functions
Here I’d like to develop a series of plotting functions that take the names or any part of the Pho4 chimera annotation as input and plot their results in a variety of ways Load the Pho4 plasmid information and merge with the reshaped data
meta <- read_tsv("../data/20220330-chimera-Pho4-makeup.tsv", col_types = "cccc")
Plotting function
# subset data
tmp <- meta %>%
filter(symbol %in% c(refs,test)) %>%
inner_join(dat1, by = "plasmid") %>%
mutate(symbol = factor(symbol, levels = c(refs, test)))
Error: Problem with `mutate()` column `symbol`.
ℹ `symbol = factor(symbol, levels = c(refs, test))`.
x factor level [3] is duplicated
Run `rlang::last_error()` to see where the error occurred.
Plot individual components
tmp %>%
pivot_longer(nGFP:nRFP, names_to = "parameter", values_to = "intensity") %>%
mutate(parameter = ordered(parameter, levels = c("nRFP", "nGFP"))) %>%
#pivot_longer(BL1.H:YL2.H, names_to = "parameter", values_to = "intensity") %>%
#mutate(parameter = ordered(parameter, levels = c("YL2.H", "BL1.H"))) %>%
ggplot(aes(x = symbol, y = intensity, group = host)) +
geom_bar(aes(fill = host), width = 0.5, alpha = 0.8,
stat = "summary", fun = "mean", position = position_dodge(0.5)) +
geom_point(aes(color = host), size = 1,
position = position_jitterdodge(dodge.width = 0.5)) +
scale_color_manual(values = c("PHO2" = "gray20", "pho2∆" = "gray40")) +
scale_fill_viridis_d(begin = 0.2, end = 0.6) +
#stat_summary(fun = "mean", geom = "crossbar", color = "red", width = 0.25,
# position = position_dodge(0.75), ) +
facet_wrap(~parameter, scale = "free_y", ncol = 1) +
xlab("Pho4 chimera") + expand_limits(y = 0) +
theme_gray(base_size = 14) +
theme(axis.text.x = element_text(angle = 30, hjust = 1, family = "mono"))
tmp %>%
#mutate(`YL2.H/BL1.H` = YL2.H/BL1.H,
mutate(`R/G` = nRFP/nGFP) %>%
ggplot(aes(x = symbol, y = `R/G`, group = host)) +
geom_bar(aes(fill = host), width = 0.5, alpha = 0.8,
stat = "summary", fun = "mean", position = position_dodge(0.5)) +
geom_point(aes(color = host), position = position_jitterdodge(dodge.width = 0.5)) +
scale_color_manual(values = c("PHO2" = "gray20", "pho2∆" = "gray40")) +
scale_fill_viridis_d(begin = 0.2, end = 0.6) +
#stat_summary(fun = "mean", color = "red", geom = "crossbar", width = 0.2,
# position = position_dodge(0.75), ) +
theme_gray(base_size = 14) + xlab("Pho4 chimera") +
theme(axis.text.x = element_text(angle = 30, hjust = 1, family = "mono"))
Next idea is to plot the ratio between the mean R/G for PHO2 and mean R/G for pho2∆, over the mean R/G for PHO2
First summarize the data.
datsum <- dat1 %>%
filter(plasmid != "NA") %>%
mutate(`R/G` = YL2.H/BL1.H, `nR/G` = nRFP/nGFP) %>%
group_by(date, plasmid, host) %>%
summarize(across(c(BL1.H, nGFP, YL2.H, nRFP, `R/G`, `nR/G`), mean), .groups = "drop") %>%
pivot_wider(names_from = host, values_from = BL1.H:`nR/G`) %>%
mutate(`pho2∆/PHO2` = `R/G_pho2∆`/`R/G_PHO2`,
`n.pho2∆/PHO2` = `nR/G_pho2∆`/`nR/G_PHO2`)
# useful to set a flag for low activity mutants
low.act.th <- datsum %>% filter(plasmid == "194") %>% summarize(across(.cols = where(is.numeric), .fns = mean)) %>% unlist()
Then extract the subset for plotting
tmpsum <- meta %>%
filter(symbol %in% c(refs,test)) %>%
inner_join(datsum, by = "plasmid") %>%
mutate(symbol = factor(symbol, levels = c(refs, test)))
Design the plot
tmpsum %>%
mutate(Activity = ifelse(`R/G_PHO2` < 2*low.act.th["R/G_pho2∆"], "low", "pass")) %>%
ggplot(aes(x = symbol, y = `pho2∆/PHO2`)) +
geom_col(aes(group = date, fill = `R/G_PHO2`), width = 0.75, color = "gray50",
position = position_dodge(0.9)) +
#geom_point(aes(color = host), position = position_jitterdodge(dodge.width = 0.5)) +
scale_fill_gradient2("Activity") +
#scale_color_manual(values = c(alpha("black",0), "red3")) +
#stat_summary(fun = "mean", color = "red", geom = "crossbar", width = 0.2,
# position = position_dodge(0.75), ) +
facet_grid(.~Activity, scales = "free_x", space = "free_x", labeller = "label_both") +
theme_bw(base_size = 14) + xlab("Pho4 chimera") +
theme(axis.text.x = element_text(angle = 30, hjust = 1, family = "mono"))
X-Y plot
p3 <- tmpsum %>%
mutate(`nR/G_PHO2` = signif(`nR/G_PHO2`, digits = 2),
`nR/G_pho2∆` = signif(`nR/G_pho2∆`, digits = 2)) %>%
ggplot(aes(x = `nR/G_PHO2`, y = `nR/G_pho2∆`, label = symbol)) +
geom_point(size = 2.5) + geom_abline(slope = 1) +
theme_gray(base_size = 14)
ggplotly(p3, tooltip = c("label", "x", "y"))